package com.essc.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * 6.21 谢明晓添加
 * 该类用于封装登录信息，成功返回success，失败返回fail
 */

@Data
public class LoginResult implements Serializable {
    //状态码200代表成功，400代表失败
    private int code;
    private String msg;
    private Object data;
    private String token;

    public static LoginResult success(Object data){ //第二层封装，这是常用方法
        return success(200,"操作成功",data);
    }

    public static LoginResult success(int code, String msg, Object data){
        LoginResult res = new LoginResult();
        res.setCode(code);
        res.setMsg(msg);
        res.setData(data);
        return res;
    }

    //带token的success方法
    public static LoginResult success(Object data, String token) {
        return success(200,"操作成功",data,token);
    }

    public static LoginResult success(int code, String msg, Object data, String token){
        LoginResult res = new LoginResult();
        res.setCode(code);
        res.setMsg(msg);
        res.setData(data);
        res.setToken(token);
        return res;
    }

    //无需data的success方法
    public static LoginResult success(){
        LoginResult res = new LoginResult();
        res.setCode(200);
        res.setMsg("操作成功");
        return res;
    }

    public static LoginResult fail(String msg){ //第二层封装，当传输失败时调用，此时data为空
        return fail(400,msg,null);
    }

    public static LoginResult fail(String msg, Object data){
        return fail(400,msg,data);
    }

    public static LoginResult fail(int code, String msg, Object data){
        LoginResult res = new LoginResult();
        res.setData(code);
        res.setMsg(msg);
        res.setData(data);
        return res;
    }
}
